package com.imageim.yimirror.common.ui.analysis;

import android.app.Activity;
import android.content.Context;
import android.os.CountDownTimer;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.imageim.yimirror.R;

/**
 * Created by Bruce.Zhou on 2018/7/3 10:29.
 * Email: 907160968@qq.com
 */

public class GenderTipView extends RelativeLayout {

    private Button btnClose;
    private CountDownTimer timer;

    public GenderTipView(Context context) {
        super(context);
        init();
    }

    public GenderTipView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public GenderTipView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View view = View.inflate(getContext(), R.layout.activity_gender_tip, this);
        btnClose = view.findViewById(R.id.btn_close_tip);
        btnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) getContext()).finish();
            }
        });

        timer = new CountDownTimer(6000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                btnClose.setText("关闭 " + millisUntilFinished / 1000 + "S");
            }

            @Override
            public void onFinish() {
                ((Activity) getContext()).finish();
            }
        };
    }

    public void startTimer() {
        timer.start();
    }

    public void destory() {
        if (timer != null) {
            timer.cancel();
        }
    }
}
